home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: Schildt <- Advanced Books
- Date: 4 Mar 1996 01:36:10 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4he6hb$ahn@solutions.solon.com>
- References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <4gnt96INN205@keats.ugrad.cs.ubc.ca> <4h4q0v$24v@redstone.interpath.net> <danpop.825687663@rscernix>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <danpop.825687663@rscernix>, Dan Pop <danpop@mail.cern.ch> wrote:
- >Sorry, I can hardly believe that. Here are two examples (originally
- >posted by Lawrence Kirby) from page 53 of the _third_ edition of C-TCR:
-
- > float f
- > printf("%f ", sizeof f);
- > printf("%d", sizeof(int));
-
- >and
-
- > void put_rec(int rec[6], FILE *fp)
- > {
- > int len;
- >
- > len = fwrite(rec, sizeof rec, 1, fp);
- > if(len != 1) printf("write error");
- > }
-
- Nit: I was the one who posted that one. Lawrence posted one where it said
- if(len<>1)...
- from the 2nd edition.
-
- Yes. Really. It was <>.
-
- >Both examples contain errors that could be made only by someone who
- >hasn't understood the language and are _very_ misleading for the
- >beginner, especially the second example (any beginner should be able
- >to spot (at least) one of the two mistakes in the first example).
-
- I will point out that both of the errors in the first one are stupid,
- perhaps mindbogglingly so, but I have made both within the last six
- months or so. If I had a nickel for every time I've typed a completely
- irrelevant format string, because I have no attention span, I'd have
- about a buck fifty.
-
- >Both mistakes appeared in the second edition of the book, as well, and
- >they are NOT typos. Ideally, the author shouldn't be allowed to
- >publish anything on a topic he is utterly unable to understand.
- >Unfortunately, the market realities of today are far from ideal :-(
-
- I could consider the "%f" a typo; it is when I do it. Believe me, I
- don't expect size_t to be a float-or-a-double. The others are
- stunning; the size_t vs int bug is subtle. The sizeof(ptr) bug
- is idiotic.
-
- >Or how interpreters should not be written, if the code is written by
- >Schildt and not pasted from another source.
-
- Well, although I didn't really look at the interpreter, I think it's
- instructive to look at the logic for a move choosing function.
-
- I will make this clear: *I DID NOT MAKE THIS UP*. I regret this;
- compared to some of my most obfuscated code, this is brilliant.
-
- void get_player_move(void)
- {
- int x, y;
-
- printf("Enter coordinates for your X: ");
- scanf("%d%d", &x, &y);
-
- x--; y--;
-
- if(matrix[x][y]!= ' '){
- printf("Invalid move, try again.\n");
- get_player_move();
- }
- else matrix[x][y] = 'X';
- }
-
- The inconsistent or stupid spacing and brace style is *not* my fault;
- I checked it twice.
-
- Can anyone find a single thing here with no mistakes? Let's see...
- No fflush after the initial printf, no check for errors on scanf, no range
- checking, undefined behavior if scanf didn't fill both values, recursion
- on an input function.
-
- The last line looks correct, but that's about *it*.
-
- And yes, the whole book is really like this.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-